package com.atguigu.cloudalibaba.service.impl;

import com.atguigu.cloudalibaba.dao.OrderDao;
import com.atguigu.cloudalibaba.domain.Order;
import com.atguigu.cloudalibaba.service.AccountService;
import com.atguigu.cloudalibaba.service.OrderService;
import com.atguigu.cloudalibaba.service.StorageService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

@Service
@Slf4j
public class OrderServiceImpl implements OrderService {
    @Autowired
    private OrderDao orderDao;
    @Autowired
    private AccountService accountService;
    @Autowired
    private StorageService storageService;
    @Override
    public void create(Order order) {
        //下订单->减库存->扣余额->改(订单)状态
        log.info("----->开始新建订单");
        orderDao.create(order);
        log.info("----->订单创建中：开始库存数量调整");
        storageService.decrease(order.getProductId(),order.getCount());
        log.info("----->订单创建中：库存数量调整完成");
        log.info("----->订单创建中：开始账户金额调整");
        accountService.decrease(order.getUserId(),order.getMoney());
        log.info("----->订单创建中：账户金额调整完成");
        //修改订单状态：0--->1
        log.info("----->订单创建中：开始修改订单状态");
        orderDao.update(order.getUserId(),0);
        log.info("----->订单创建中：修改订单状态完成");
        log.info("----->订单创建完成⭐⭐⭐");
    }
}
